<?php

namespace app\admin\model;

use think\Model;

class User_role extends Model
{
    public function add($rid=[],$uid)
    {
        $list = [];
        if (is_array($rid)){
            foreach ($rid as $val){
                $list[] = ['rid'=>$val ,'uid'=>$uid];
            }
           $this->saveAll($list);
            return 1;
        }
        return 0;
    }

    public static function allRid($uid)
    {
        $where = function ($query) use ($uid){
            $query->field(['rid'])->where(['uid'=>$uid]);
        };
        $arr = parent::all($where);
        $rid = [];
        foreach ($arr as $val){
            $rid[] = $val->getData()['rid'];
        }
        return $rid;
    }


}
